package com.example.springbootredis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

/**
 订阅配置 channel1是频道，可以多个
 也可以patternToppic
 */
@Configuration
public class MyRedisMessageListenerContainer {
  /*  @Bean
    Apple xx() {
        return new Apple();
    }
    @Bean
    Cat cat() {
        return new Cat();
    }*/
    @Bean
    MessageListenerAdapter messageListener() {
        return new MessageListenerAdapter(new MySubcribe());
    }

    @Bean
    RedisMessageListenerContainer redisContainer(RedisConnectionFactory factory) {
        final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(factory);
        container.addMessageListener(messageListener(), new ChannelTopic("channel1"));
        return container;
    }
}